package cn.pconline.autoclub.task.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.PropertyConfigurator;

import cn.pconline.autoclub.task.FileUtils;

public class LogUtils {
    public static void initLog() {
        FileInputStream istream = null;
        try {
            Properties props = new Properties();
            istream = new FileInputStream(FileUtils.confDir + File.separator + FileUtils.log4jName);
            props.load(istream);
            istream.close();
            String logFile = props.getProperty("log4j.appender.autoclubtask.File");//设置路径
            props.setProperty("log4j.appender.logfile.File", new File(logFile).getAbsolutePath());
            PropertyConfigurator.configure(props);//装入log4j配置信息
        } catch (FileNotFoundException ex) {
            System.err.println("need config file:" + FileUtils.confDir + File.separator + FileUtils.log4jName);
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            try {
                istream.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}
